<?php
/**
 * @version     1.0.0
 * @package     com_travel
 * @copyright   Copyright (C) 2013. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 * @author      thinh <dinhducthinh88@yahoo.com> - http://
 */

// No direct access.
defined('_JEXEC') or die;

jimport('joomla.application.component.controllerform');
JTable::addIncludePath(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_travel'.DS.'tables');
/**
 * Tour list controller class.
 */
class TravelControllerField extends JControllerForm
{
	function __construct() 
	{
        $this->view_list = 'fields';
        parent::__construct();
    }
     
     /**
     * Override Fucntion postSaveHook
	 * Function that allows child controller access to model data
	 * after the data has been saved.
	 */
     public function postSaveHook($model, $validData)
     {
     	$post 			= JRequest::get('post');
     	$field 			= $post['jform'];	
     	$field_type		= $post['jform']['field_type'];
     	$fieldNames  	= $post['vNames'];
     	$fieldValues 	= $post['vValues'];
     	
     	$item 			= $model->getItem();
     	$fieldid 		= $item->get('id');
     	
     	$model->addTourField($field);
     	$model->saveFieldValues($field_type, $fieldNames, $fieldValues, $fieldid);
     }
     
    /*  protected function allowEdit($data = array(), $key = 'id')
     {
     	// Initialise variables.
     	$recordId = (int) isset($data[$key]) ? $data[$key] : 0;
     	$user = JFactory::getUser();
     	$userId = $user->get('id');
     	// Check general edit permission first.
     	if ($user->authorise('core.edit', 'com_travel.field.' . $recordId))
     	{
     		return true;
     	}
     
     	// Fallback on edit.own.
     	// First test if the permission is available.
     	if ($user->authorise('core.edit.own', 'com_travel.field.' . $recordId))
     	{
     		// Now test the owner is the user.
     		$ownerId = (int) isset($data['created_by']) ? $data['created_by'] : 0;
     		if (empty($ownerId) && $recordId)
     		{
     			// Need to do a lookup from the model.
     			$record = $this->getModel()->getItem($recordId);
     
     			if (empty($record))
     			{
     				return false;
     			}
     
     			$ownerId = $record->created_by;
     		}
     
     		// If the owner matches 'me' then do the test.
     		if ($ownerId == $userId)
     		{
     			return true;
     		}
     	}
     
     	// Since there is no asset tracking, revert to the component permissions.
     	return parent::allowEdit($data, $key);
     } */
      
}